package com.briup.jz.web.controller;

import com.briup.jz.bean.Category;
import com.briup.jz.bean.CategoryExample;
import com.briup.jz.bean.extend.CategoryExtend;
import com.briup.jz.dao.extend.CategoryExtendMapper;
import com.briup.jz.service.ICategoryService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: jz
 * @description: 栏目控制器
 * @author: rendc
 * @create: 2020-06-11 16:41
 **/
@RestController
@RequestMapping("/category")
@Api(description = "产品类别管理接口")
public class CategoryController {
    @Autowired
    private ICategoryService categoryService;

    @ApiOperation(value = "查看全部")
    @GetMapping("findAll")
    public Message findAll(){
        List<Category> list=categoryService.findAll();
        return MessageUtil.success(list);
    }


    @ApiOperation(value = "保存或修改")
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Category category){
        categoryService.saveOrUpdate(category);
        return MessageUtil.success("已保存");
    }

    @ApiOperation(value = "通过ID删除")
    @GetMapping("deleteById")
    public Message deleteById(long id){
        categoryService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

    @ApiOperation(value = "查看全部及相关")
    @GetMapping("findAllWithChild")
    public Message findAllWithChild(){
        List<CategoryExtend> list = categoryService.findAllWithChild();
        return MessageUtil.success(list);

    }
}

















